#read in oil spill data
oil_spill <- read_sf(here("Oil_Spill_Incident_Tracking-shp"), layer = "Oil_Spill_Incident_Tracking") %>% 
  clean_names() %>% 
  rename(county = localecoun)

#check the refrence system
#st_crs(oil_spill)

#read in ca county boundaries
ca_county <- read_sf(here("ca_shape"), layer = "CA_Counties_TIGER2016"
) %>% 
  clean_names()

#st_crs(ca_county)

#transform to match
ca_county <- st_transform(ca_county, st_crs(oil_spill))
tmap_mode("view")

tm_shape(oil_spill) +
  tm_dots("county")
tm_shape(ca_county) +
  tm_fill("name", palette = "YlOrBr", show.legend = FALSE) +
  tm_shape(oil_spill) +
  tm_dots(aes(color = "darkred")) 
#looking at inland spills counts per county
inland <- oil_spill %>% 
  filter(inlandmari == "Inland")

ca_inland <- ca_county %>% 
  st_join(inland)

inland_spill <- ca_inland %>% 
  count(county)
 

ggplot(data = inland_spill) +
  geom_sf(aes(fill = n), color = "white", size = 0.1) +
  scale_fill_gradientn(colors = c("lightgray","darkorange","darkred")) +
  theme_minimal() +
  labs(fill = "Number of Oil Spills per County",
       title = "2008 Inland California Oil Spills")